package com.gengao.springbootcase.controller;

import com.gengao.springbootcase.pojo.Result;
import com.gengao.springbootcase.pojo.User;
import com.github.pagehelper.PageInfo;
import org.apache.coyote.ActionHook;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;

import static java.lang.System.out;

@RestController
public class Hello {
    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public Result sayHello(){
        String res="Hello Spring";
        return Result.success(res);
    }
    @RequestMapping(value = "/simpleParam",method = RequestMethod.POST)
    public Result testSimpleParam(@RequestParam(value = "name",required = false) String username,Integer age){
        out.println("username="+username+",age="+age);
        return Result.success();
    }

    @RequestMapping(value = "/simplePojo",method = RequestMethod.POST)
    public Result testSimplePojo(User user){
        out.println(user);
        return Result.success();
    }
    @RequestMapping(value = "/complexPojo",method = RequestMethod.POST)
    public Result testComplexPojo(User user){
        out.println(user);
        return Result.success();
    }

    @RequestMapping(value = "/arrayParam",method = RequestMethod.POST)
    public Result testArray(String[] hobby){

        out.println(Arrays.toString(hobby));
        return Result.success();
    }

    @RequestMapping(value = "/timeParam",method = RequestMethod.POST)
    public Result testTimeParam(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime updateTime){
        System.out.println(updateTime);
        return Result.success();
    }


    //Json格式
    @RequestMapping(value = "/jsonParam",method = RequestMethod.POST)
    public Result testJsonParam(@RequestBody User user){
        System.out.println(user);
        return Result.success();
    }

    @RequestMapping(value = "/pathParam/{id}",method = RequestMethod.POST)
    public Result testPathParam(@PathVariable Integer id){
        System.out.println("id:"+id);
        return Result.success();
    }
}
